package framework.ui;

import org.openems.entity.Key;

import framework.DomainService;
import javafx.event.EventHandler;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;

public class EmsEditBox extends Pane {
	private ITextFieldListener listener;
	
	public EmsEditBox(final Key key, DomainService service) {
		// Title
		final Label title = createTitle();
		
		final TextField textField = crateTextField();
		
		HBox hbox = new HBox();
		this.getChildren().add(hbox);
		hbox.getChildren().add(title);
		hbox.getChildren().add(textField);
		
		textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
			@Override
			public void handle(KeyEvent arg0) {
				listener.keyPressed(arg0.getCode());
			}			
		});
		
		new EmsEditConnector(new ILabel() {
			@Override
			public void setText(String name) {
				title.setText(name);
			}
		}, new ITextField() {

			@Override
			public void setText(String valueText) {
				textField.setText(valueText);
			}

			@Override
			public String getText() {
				return textField.getText();
			}

			@Override
			public void setOnKeyPressed(ITextFieldListener iTextFieldListener) {
				listener = iTextFieldListener;
			}
			
		}, service, key);

	}

	protected TextField crateTextField() {
		return new TextField();
	}

	protected Label createTitle() {
		return new Label();
	}

}
